// Selection sort va su dung con tro ham
#include <iostream.h>


bool asscend(int a, int b){
	return a < b;
}
bool descend(int a, int b){
	return a > b;
}

void swap(int &a, int &b){
	int tem = a; 
	a = b;
	b = tem;
}

void selectionSort(int arr[], int n, bool (*compare)(int, int)){
	for(int i = 0; i < n-1; i++){
		int maxOrmin = i;
		for(int j = i + 1; j < n; j++){
			if(compare(arr[j], arr[maxOrmin]))
				maxOrmin = j;
		}
		swap(arr[i], arr[maxOrmin]);
	}
}

int main(){	
	char c;
	int arr[] = {
	23, 11, 21, 45, 24, 18, 79, 90, 234, 112	
	};
	int size = 10;
	
	cout<<"enter c "; cin>>c;
	if(c == 'a') selectionSort(arr, size, asscend);
	else selectionSort(arr, size, descend);
	for(int i = 0; i < 10; i++) cout<<arr[i]<<" ";
	return 0;
	
}























/*
int ham1(int a, int b){
	return a + b;
}
int ham2(int a, int b){
	return a - b;
}

void ham3(int arr[], int n, int(*pHam)(int x, int y)){
	int tem;
	for(int i = 0; i < n-1; i++){
		for(int j = 0; j < n; j++){
			if(arr[i] > arr[j])
			tem = pHam(arr[i], arr[j]);
		}
		cout<<tem<<endl;
	}
}

int main(){
	int arr[] = {
		23, 43, 11, 90, 22, 56, 78
	};
	int size = 7;
	char c;
	cout<<"enter c  : "; cin>>c;
	if(c=='m') ham3(arr, 7, ham1);
	else ham3(arr, 7, ham2);
	return 0;
}*/